import 'package:flutter/material.dart';

class Base extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _BaseState();
  }
}
 
class _BaseState extends State<Base> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  Animation<double> _withHeight;

  @override
  void initState() {
    super.initState();

    // 时长
    _controller = AnimationController(
      duration: Duration(seconds: 3),
      vsync: this,
    );

    // 动画曲线
    final _curve = CurvedAnimation(parent: _controller, curve: Curves.bounceInOut);

    // 图片宽高从0变到300
    _withHeight = Tween(begin: 0.0, end: 300.0).animate(_curve);

    // 侦听
    _withHeight.addListener(() {
      setState(() {
      });
    });

    // 启动动画(正向执行)
    _controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('基础用法'),
      ),
      body: Center(
        child: Image.asset('image/icon-60.png',
          width: _withHeight.value,
          height: _withHeight.value,
          fit: BoxFit.fill,
        ),
      ),
    );
  }

  @override
  void dispose() {
    // 路由销毁时需要释放动画资源
    _controller.dispose();

    super.dispose();
  }
}